package com.exampl.health.entity;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 健康数据实体类
 */
public class HealthData {
    private Integer dataId;            // 数据ID
    private Integer userId;            // 用户ID
    private Date recordDate;           // 记录日期
    private BigDecimal height;         // 身高(单位:厘米)
    private BigDecimal weight;         // 体重(单位:千克)
    private String bloodPressure;      // 血压(格式: 120/80)
    private Integer heartRate;         // 心率
    private BigDecimal bloodSugar;     // 血糖
    private BigDecimal temperature;    // 体温(单位:摄氏度)
    private String notes;              // 备注
    private Date createTime;           // 创建时间

    // 无参构造方法
    public HealthData() {
    }

    // 带参构造方法
    public HealthData(Integer userId, Date recordDate, BigDecimal height,
                      BigDecimal weight, String bloodPressure, Integer heartRate,
                      BigDecimal bloodSugar, BigDecimal temperature, String notes) {
        this.userId = userId;
        this.recordDate = recordDate;
        this.height = height;
        this.weight = weight;
        this.bloodPressure = bloodPressure;
        this.heartRate = heartRate;
        this.bloodSugar = bloodSugar;
        this.temperature = temperature;
        this.notes = notes;
        this.createTime = new Date();
    }

    // Getter和Setter方法
    public Integer getDataId() {
        return dataId;
    }

    public void setDataId(Integer dataId) {
        this.dataId = dataId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Date getRecordDate() {
        return recordDate;
    }

    public void setRecordDate(Date recordDate) {
        this.recordDate = recordDate;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public void setHeight(BigDecimal height) {
        this.height = height;
    }

    public BigDecimal getWeight() {
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public String getBloodPressure() {
        return bloodPressure;
    }

    public void setBloodPressure(String bloodPressure) {
        this.bloodPressure = bloodPressure;
    }

    public Integer getHeartRate() {
        return heartRate;
    }

    public void setHeartRate(Integer heartRate) {
        this.heartRate = heartRate;
    }

    public BigDecimal getBloodSugar() {
        return bloodSugar;
    }

    public void setBloodSugar(BigDecimal bloodSugar) {
        this.bloodSugar = bloodSugar;
    }

    public BigDecimal getTemperature() {
        return temperature;
    }

    public void setTemperature(BigDecimal temperature) {
        this.temperature = temperature;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    // 计算BMI指数的方法
    public BigDecimal calculateBMI() {
        if (height != null && weight != null && height.compareTo(BigDecimal.ZERO) > 0) {
            // BMI = 体重(kg) / (身高(m) * 身高(m))
            BigDecimal heightInMeter = height.divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
            return weight.divide(heightInMeter.multiply(heightInMeter), 2, BigDecimal.ROUND_HALF_UP);
        }
        return null;
    }

    // 判断体温是否正常的方法
    public String getTemperatureStatus() {
        if (temperature == null) {
            return "未测量";
        }

        // 正常体温范围：36.1°C - 37.2°C
        if (temperature.compareTo(new BigDecimal("36.1")) >= 0 &&
                temperature.compareTo(new BigDecimal("37.2")) <= 0) {
            return "正常";
        } else if (temperature.compareTo(new BigDecimal("37.2")) > 0) {
            return "偏高";
        } else {
            return "偏低";
        }
    }

    @Override
    public String toString() {
        return "HealthData{" +
                "dataId=" + dataId +
                ", userId=" + userId +
                ", recordDate=" + recordDate +
                ", height=" + height +
                ", weight=" + weight +
                ", bloodPressure='" + bloodPressure + '\'' +
                ", heartRate=" + heartRate +
                ", bloodSugar=" + bloodSugar +
                ", temperature=" + temperature +
                ", notes='" + notes + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}